//
//  BillTableViewCell.m
//  jingdongfang
//
//  Created by 郝志宇 on 16/8/11.
//  Copyright © 2016年 ZhiYu Hao. All rights reserved.
//

#import "BillTableViewCell.h"
#import "IGWalletBillDetail.h"

@interface BillTableViewCell () {
    UILabel *time;
    UIImageView *imageView;
    UILabel *name;
    UILabel *type;
    UILabel *price;
    NSString *c;
}

@end

@implementation BillTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self _initViews];
    }
    return self;
}

- (void)_initViews {
    time = [[UILabel alloc] initWithFrame:CGRectZero];
    time.numberOfLines = 2;
    time.font = [UIFont systemFontOfSize:13];
    time.textColor = [UIColor grayColor];
    [self.contentView addSubview:time];
    
    imageView = [[UIImageView alloc] initWithFrame:CGRectZero];
    imageView.contentMode = UIViewContentModeScaleAspectFit;
    [self.contentView addSubview:imageView];
    
    name = [[UILabel alloc] initWithFrame:CGRectZero];
    name.font = [UIFont systemFontOfSize:16];
    [self.contentView addSubview:name];
    
    type = [[UILabel alloc] initWithFrame:CGRectZero];
    type.font = [UIFont systemFontOfSize:14];
    type.textColor = [UIColor grayColor];
    [self.contentView addSubview:type];
    
    price = [[UILabel alloc] initWithFrame:CGRectZero];
    price.font = [UIFont systemFontOfSize:16];
    [self.contentView addSubview:price];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    IGWalletBillDetail *info = self.data;
    
    time.text = [NSDate timestampToString:info.createdAt Format:@"MM-dd\nHH:mm"];
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    paragraphStyle.lineSpacing = 6;
    NSAttributedString *str = [[NSAttributedString alloc] initWithString:time.text attributes:@{NSParagraphStyleAttributeName:paragraphStyle}];
    time.attributedText = str;
    [time sizeToFit];
    time.x = 10;
    time.width = time.width + 6;
    time.centerY = self.height/2;
    
    if ([info.type integerValue]==1)
    { //收
//        imageView.image = [UIImage imageNamed:@"图层-4"];
        imageView.image = [UIImage imageNamed:NSLocalizedString(@"get",nil)];
        price.textColor =[UIColor appColor];
        c = @"+";
    }
    else if ([info.type integerValue]==2)
    {  //支
//        imageView.image = [UIImage imageNamed:@"图层-5"];
        imageView.image = [UIImage imageNamed:NSLocalizedString(@"pay",nil)];
        price.textColor = [UIColor blackColor];
        c = @"-";
    }else if ([info.type integerValue]==3){
        //提现
//        imageView.image = [UIImage imageNamed:@"图层-5"];
        imageView.image = [UIImage imageNamed:NSLocalizedString(@"pay",nil)];
        price.textColor = [UIColor blackColor];
        c = @"-";
    }
    imageView.frame = CGRectMake(time.right+12, 12, self.height-24, self.height-24);
    name.text = info.tittle.length>0?info.tittle:@" ";
    [name sizeToFit];
    

    type.text=[NSString stringWithFormat:@"%@",info.typesName];

    [type sizeToFit];
    
    name.x = imageView.right+5;
    name.y = (self.height-name.height-type.height-8)/2;
    name.width = 200;
    
    type.x = name.x;
    type.top = name.bottom+8;
    
    price.text = [c stringByAppendingString:[NSString stringWithFormat:@"%.2f", [info.amount.length>0?info.amount:@"0" floatValue]]];
    [price sizeToFit];
    
    price.right = self.width-15;
    price.centerY = self.height/2 + 5;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
